<script setup lang="ts">
import categoryConfigStore from "@/store/modules/categoryConfig";
import { onMounted } from "vue";
//接收父组件的属性scene
defineProps<{
  scene: number;
}>();
let categoryConfig = categoryConfigStore();
onMounted(() => {
  selectCategory1();
});
//请求一级分类数据
const selectCategory1 = async () => {
  categoryConfig.getCategory1List();
};
//请求二级分类数据
const selectCategory2 = async () => {
  categoryConfig.clearCategory2And3();
  categoryConfig.getCategory2List();
};
//请求三级分类数据
const selectCategory3 = async () => {
  categoryConfig.clearCategory3();
  categoryConfig.getCategory3List();
};
</script>

<template>
  <el-card>
    <el-form :inline="true" class="classify-form-inline">
      <el-form-item label="一级分类">
        <el-select
          :disabled="categoryConfig.isDisabled"
          v-model="categoryConfig.category1Id"
          @change="selectCategory2"
          clearable
        >
          <el-option
            v-for="(item, index) in categoryConfig.category1List"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryConfig.category2Id"
          :disabled="categoryConfig.isDisabled"
          @change="selectCategory3"
          clearable
        >
          <el-option
            v-for="(item, index) in categoryConfig.category2List"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          v-model="categoryConfig.category3Id"
          :disabled="categoryConfig.isDisabled"
          clearable
        >
          <el-option
            v-for="(item, index) in categoryConfig.category3List"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style lang="scss" scoped>
.classify-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
